package com.person.jiaiplan.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.person.jiaiplan.mapper.AchievementLogsMapper;
import com.person.jiaiplan.pojo.entity.AchievementLogs;
import com.person.jiaiplan.service.AchievementLogsService;
import org.springframework.stereotype.Service;

import java.util.Date;

@Service
public class AchievementLogsServiceImpl extends ServiceImpl<AchievementLogsMapper, AchievementLogs> implements AchievementLogsService {

    @Override
    public Boolean saveOrUpdateAchievement(AchievementLogs achievementLogs) {

        if (this.count(Wrappers.<AchievementLogs>lambdaQuery()
                .eq(AchievementLogs::getScheduleId, achievementLogs.getScheduleId())
                .eq(AchievementLogs::getMkdir, achievementLogs.getMkdir())
                .eq(AchievementLogs::getFileName, achievementLogs.getFileName())) <= 0) {
            this.save(achievementLogs);
        } else {
            AchievementLogs achievement = this.getOne(Wrappers.<AchievementLogs>lambdaQuery()
                    .eq(AchievementLogs::getScheduleId, achievementLogs.getScheduleId())
                    .eq(AchievementLogs::getMkdir, achievementLogs.getMkdir())
                    .eq(AchievementLogs::getFileName, achievementLogs.getFileName()));
            // 目前就是修改备注和更新日期
            achievement.setRemark(achievementLogs.getRemark());
            achievement.setUpdateTime(new Date());
            this.updateById(achievement);
        }
        return true;
    }
}
